<template>
<view>
	<view class="select">   
	<view></view>
	    <input class="weui-input1" @input="search" placeholder="搜索会员"/>
	</view>
	<view class="top">
		<view @click="select(0)" class="header_select border_right" :class="lv == 0 ? 'border-bottom' : ''">全部</view>
		<view @click="select('A')" class="header_select border_right" :class="lv == 'A' ? 'border-bottom' : ''">A类会员</view>
		<view @click="select('B')" class="header_select border_right" :class="lv == 'B' ? 'border-bottom' : ''">B类会员</view>
		<view @click="select('C')" class="header_select border_right" :class="lv == 'C' ? 'border-bottom' : ''">C类会员</view>
		<view @click="select('D')" class="header_select" :class="lv == 'D' ? 'border-bottom' : ''">D类会员</view>
	</view>
	<view class="table">
		<table border="0" width="95%" cellspacing="0" cellpadding="0">
			<tr>
				<td>客户姓名</td>
				<td>客户电话</td>
				<td>客户等级</td>
			</tr>
			<tr v-for="(item,index) in list" :key="index" @click="jump('./file',item.id)">
				<td>{{item.username}}</td>
				<td>{{item.phone}}</td>
				<td>{{item.lv}}</td>
			</tr>
		</table>
	</view>
	
	<navigator url="/manage/member/add" open-type="navigate"  v-if="oaRole == 1 || oaRole == 3">
		<button class="buttonClass">添加会员</button>
	</navigator>
</view>
</template>
<script>
import request from '@/util/request.js'
export default {
	data() {
		return {
			//oaRole 1:店长2:员工3:商户
			oaRole:0,
			list:[],
			page:1,
			pageShow:true,
			keyWord:'',
			lv:0,
		}
	},
	onLoad:function(){
		uni.showLoading({
		    title: '加载中'  
		});
		this.oaRole = uni.getStorageSync('oaRole')
		this.getList();
	},
	methods: {
		getList:function(){
		    var data = {
		        'oa_id':uni.getStorageSync('oa_id'),
				'page':this.page,
				'keyword':this.keyWord,
				'lv':this.lv
		    }
		    var that = this
			request({
				url: 'manage/member/list',
				method: 'get',
				data:data,
				success: (res) => {
					uni.hideLoading();
					if(res.data.code == 1){
						if(res.data.data.last_page <= that.page){
							that.pageShow = false
						}
						if(that.page == 1){
							that.list = res.data.data.data
						}else{
							var list = that.list
							that.list = list.concat(res.data.data.data)
						}
					}
				},
			})
		},
		onReachBottom: function(){
			if(this.pageShow){
				 //当前不是最后一页可加载
				 this.page = this.page + 1
				 uni.showLoading()
				 this.getList();
			}
		},
		search:function(e){
			this.keyWord = e.detail.value
			this.page = 1
			this.pageShow = true
			uni.showLoading()
			this.getList();
		},
		jump:function(url,id){
			uni.navigateTo({
			  url:url+'?id='+id
			})
		},
		select:function(key){
			this.lv = key
			this.page = 1
			this.pageShow = true
			uni.showLoading()
			this.getList();
		}
	}
}
</script>
<style>
@import url("../css/member/index.css");
</style>